package com.cxl.price.top.service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Service;

import com.taobao.api.ApiException;
import com.taobao.api.request.ItemAddRequest;
import com.taobao.api.request.ItemGetRequest;
import com.taobao.api.request.ItemImgDeleteRequest;
import com.taobao.api.request.ItemImgUploadRequest;
import com.taobao.api.request.ItemRecommendAddRequest;
import com.taobao.api.request.ItemRecommendDeleteRequest;
import com.taobao.api.request.ItemUpdateDelistingRequest;
import com.taobao.api.request.ItemUpdateListingRequest;
import com.taobao.api.request.ItemUpdateRequest;
import com.taobao.api.request.ItemsInventoryGetRequest;
import com.taobao.api.request.ItemsOnsaleGetRequest;
import com.taobao.api.response.ItemAddResponse;
import com.taobao.api.response.ItemGetResponse;
import com.taobao.api.response.ItemImgDeleteResponse;
import com.taobao.api.response.ItemImgUploadResponse;
import com.taobao.api.response.ItemRecommendAddResponse;
import com.taobao.api.response.ItemRecommendDeleteResponse;
import com.taobao.api.response.ItemUpdateDelistingResponse;
import com.taobao.api.response.ItemUpdateListingResponse;
import com.taobao.api.response.ItemUpdateResponse;
import com.taobao.api.response.ItemsInventoryGetResponse;
import com.taobao.api.response.ItemsOnsaleGetResponse;


/**
 * 商品类操作
 * @author Administrator
 *
 */
@Service
public class TopItemResponseService extends TopBaseService {
	
	

	/**
	 * 获得在售商品response 带参数 默认得到 2000个 传入req参数可以改变这个值
	 * @return
	 * @throws ApiException 
	 */
	public ItemsOnsaleGetResponse getItemsOnsaleGetResponse(ItemsOnsaleGetRequest req) throws ApiException 
	{
		ItemsOnsaleGetRequest def=new ItemsOnsaleGetRequest();
		def.setFields("approve_status,num_iid,title,nick,type,cid,pic_url,num,props,valid_thru,list_time,price,has_discount,has_invoice,has_warranty,has_showcase,modified,delist_time,postage_id,seller_cids,outer_id");
		def.setPageSize(200L);
		req=getNewTaobaoRequest(req, def);
		return getTaobaoResponse(req!=null?req:def);
	}

	/**
	 * 获得在售商品response 不带参数
	 * @return
	 * @throws ApiException
	 */
	public ItemsOnsaleGetResponse getItemsOnsaleGetResponse() throws ApiException 
	{
		return getItemsOnsaleGetResponse(null);
	}
	
	
	/**
	 * 获得库存商品response 带参数 默认得到 2000个 传入req参数可以改变这个值
	 * @return
	 * @throws ApiException 
	 */
	public ItemsInventoryGetResponse getItemsInventoryGetResponse(ItemsInventoryGetRequest req) throws ApiException 
	{
		ItemsInventoryGetRequest def=new ItemsInventoryGetRequest();
		def.setFields("approve_status,num_iid,title,nick,type,cid,pic_url,num,props,valid_thru,list_time,price,has_discount,has_invoice,has_warranty,has_showcase,modified,delist_time,postage_id,seller_cids,outer_id");
		def.setPageSize(200L);
		req=getNewTaobaoRequest(req, def);
		return getTaobaoResponse(req!=null?req:def);
	}

	/**
	 * 获得库存商品response 不带参数
	 * @return
	 * @throws ApiException
	 */
	public ItemsInventoryGetResponse getItemsInventoryGetResponse() throws ApiException 
	{
		return getItemsInventoryGetResponse(null);
	}
	
	//抓取的商品变为淘宝商品
	public void grab2TbItem(){
		
	}
	
	
	/**
	 * 上货response 
	 * @param req
	 * @return  上架response
	 * @throws Exception 
	 */
	public ItemAddResponse getItemAddResponse(ItemAddRequest req,HttpServletRequest request) throws Exception
	{
		ItemAddRequest def=new ItemAddRequest();
		def.setNum(100L);
		def.setType("fixed");
		def.setStuffStatus("new");
		def.setLocationState("湖北");
		def.setLocationCity("武汉");
		def.setApproveStatus("onsale");
		
		
		/**
		 * 运费承担方式。可选值:seller（卖家承担）,buyer(买家承担);
		 * 默认值:seller。卖家承担不用设置邮费和postage_id.买家承担的时候，
		 * 必填邮费和postage_id 如果用户设置了运费模板会优先使用运费模板，
		 * 否则要同步设置邮费（post_fee,express_fee,ems_fee） 
		 */
		def.setFreightPayer("seller");
		def.setValidThru(7L);//有效期。可选值:7,14;单位:天;默认值:14 
		def.setHasInvoice(true);//是否有发票。可选值:true,false (商城卖家此字段必须为true);默认值:false(无发票)
		def.setHasWarranty(true);//是否有保修。可选值:true,false;默认值:false(不保修) 
		def.setHasShowcase(true);//橱窗推荐。可选值:true,false;默认值:false(不推荐) 
		 
		def.setHasDiscount(true);//会员打折
		def.setPostFee("20");//平邮费用
		def.setExpressFee("10");//快递费用
		def.setEmsFee("20");//ems
		Date dateTime = SimpleDateFormat.getDateTimeInstance().parse("2000-01-01 00:00:00");
		
		/*def.setListTime(dateTime);*/ //定时上架
	//	FileItem fItem = new FileItem(new File("fileLocation"));
	//	def.setImage(fItem);
		/*def.setPostageId(775752L);*///设置运费模板
		/*def.setAuctionPoint(5L);
		def.setPropertyAlias("pid:vid:别名;pid1:vid1:别名1");
		def.setInputPids("pid1,pid2,pid3");
		def.setSkuProperties("pid:vid;pid:vid");
		def.setSkuQuantities("2,3,4");
		def.setSkuPrices("200.07");
		def.setSkuOuterIds("1234,1342");
		def.setLang("zh_CN");
		def.setOuterId("12345");
		def.setProductId(123456789L);
		def.setPicPath("uploaded/i7/T1rfxpXcVhXXXH9QcZ_033150.jpg");
		def.setAutoFill("time_card");
		def.setInputStr("耐克;耐克系列;科比系列;科比系列;2K5,Nike乔丹鞋;乔丹系列;乔丹鞋系列;乔丹鞋系列;");
		def.setIsTaobao(true);
		def.setIsEx(true);
		def.setIs3D(true);
		def.setSellPromise(true);
		def.setAfterSaleId(47758L);
		def.setCodPostageId(53899L);
		def.setIsLightningConsignment(true);
		def.setWeight(100L);*///
		req=getNewTaobaoRequest(req, def);
		return getTaobaoResponse(req,request);
	}
	
	/**
	 * 
	 * @param req
	 * @return 上货response
	 * @throws Exception 
	 */
	public ItemAddResponse getItemAddResponse(HttpServletRequest request) throws Exception
	{
		return getItemAddResponse(null, request);
	}
	/**
	 * 获得下架response 
	 * @param req
	 * @return  下架response
	 * @throws ApiException
	 * @throws ParseException
	 */
	public ItemUpdateDelistingResponse getItemUpdateDelistingResponse(Long num_iid) throws ApiException, ParseException
	{
		ItemUpdateDelistingRequest req =new ItemUpdateDelistingRequest();
		req.setNumIid(num_iid);
		return getTaobaoResponse(req);
	}
	
	/**
	 * 获得上架response 
	 * @param req
	 * @return  上架response
	 * @throws ApiException
	 * @throws ParseException
	 */
	public ItemUpdateListingResponse getItemUpdateListingResponse(Long num_iid,Long num) throws ApiException, ParseException
	{
		ItemUpdateListingRequest req =new ItemUpdateListingRequest();
		req.setNumIid(num_iid);
		req.setNum(num);
		return getTaobaoResponse(req);
	}
	
	
	
	/**
	 * 
	 * @param req
	 * @return 修改商品信息response
	 * @throws ApiException
	 * @throws ParseException
	 */
	public ItemUpdateResponse getItemUpdateResponse(ItemUpdateRequest req) throws ApiException ,ParseException
	{
		return getTaobaoResponse(req);
	}
	
	/**
	 * 获得单个商品信息response 带参数
	 * @return
	 * @throws ApiException 
	 */
	public ItemGetResponse getItemGetResponse(Long num_iid) throws ApiException 
	{
		ItemGetRequest req=new ItemGetRequest();
		req.setFields("detail_url,props_name,volume,num_iid,title,nick,type,cid,seller_cids,props,input_pids,input_str,desc,pic_url,num,valid_thru,list_time,delist_time,stuff_status,location,price,post_fee,express_fee,ems_fee,has_discount,freight_payer,has_invoice,has_warranty,has_showcase,modified,increment,approve_status,postage_id,product_id,auction_point,property_alias,item_img,prop_img,sku,video,outer_id,is_virtual,item_imgs");
		req.setNumIid(num_iid);
		return getTaobaoResponse(req);
	}
	
	
	public ItemGetRequest getItemGetRequest(Long num_iid) throws ApiException 
	{
		ItemGetRequest req=new ItemGetRequest();
		req.setFields("detail_url,props_name,volume,num_iid,title,nick,type,cid,seller_cids,props,input_pids,input_str,desc,pic_url,num,valid_thru,list_time,delist_time,stuff_status,location,price,post_fee,express_fee,ems_fee,has_discount,freight_payer,has_invoice,has_warranty,has_showcase,modified,increment,approve_status,postage_id,product_id,auction_point,property_alias,item_img,prop_img,sku,video,outer_id,is_virtual,item_imgs");
		req.setNumIid(num_iid);
		return req;
	}

	
	
	

	
	
	
	/**
	 * 上传一个宝贝图片
	 * @return
	 * @throws ApiException 
	 */
	public ItemImgUploadResponse  getItemImgUploadResponse  (ItemImgUploadRequest  req) throws ApiException 
	{
		ItemImgUploadRequest def=new ItemImgUploadRequest();
		req=getNewTaobaoRequest(req, def);
		return getTaobaoResponse(req!=null?req:def);
	}

	/**
	 * 上传一个宝贝图片response 不带参数
	 * @return
	 * @throws ApiException
	 */
	public ItemImgUploadResponse   getItemImgUploadResponse  () throws ApiException 
	{
		return getItemImgUploadResponse (null);
	}
	
	
	/**
	 * 上传一个宝贝图片
	 * @return
	 * @throws ApiException 
	 */
	public ItemImgDeleteResponse  getItemImgDeleteResponse  (ItemImgDeleteRequest  req) throws ApiException 
	{
		ItemImgDeleteRequest def=new ItemImgDeleteRequest();
		req=getNewTaobaoRequest(req, def);
		return getTaobaoResponse(req!=null?req:def);
	}
	
	
	
	
	
	/**
	 * 推窗推荐一个
	 * @return
	 * @throws ApiException 
	 */
	public ItemRecommendAddResponse  getItemRecommendAddResponse  (ItemRecommendAddRequest  req) throws ApiException 
	{
		ItemRecommendAddRequest def=new ItemRecommendAddRequest();
		req=getNewTaobaoRequest(req, def);
		return getTaobaoResponse(req!=null?req:def);
	}
	
	
	
	
	/**
	 * 取消推荐一个
	 * @return
	 * @throws ApiException 
	 */
	public ItemRecommendDeleteResponse  getItemRecommendDeleteResponse (ItemRecommendDeleteRequest  req) throws ApiException 
	{
		ItemRecommendDeleteRequest def=new ItemRecommendDeleteRequest();
		req=getNewTaobaoRequest(req, def);
		return getTaobaoResponse(req!=null?req:def);
	}
	
	
	
	
}
